package com.softtown.modules.dapai.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softtown.common.service.impl.BaseServiceImpl;
import com.softtown.common.utils.ConvertUtils;
import com.softtown.modules.dapai.dao.CompWarehouseDao;
import com.softtown.modules.dapai.dto.CompWarehouseDTO;
import com.softtown.modules.dapai.entity.CompWarehouseEntity;
import com.softtown.modules.dapai.service.CompWarehouseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @Author: Ding Ya Yong
* @Description: 仓库信息
* @date: 2022/1/2 11:38
* @Param:
* @return:
*/

@Service
public class CompWarehouseServiceImpl extends
        BaseServiceImpl<CompWarehouseDao, CompWarehouseEntity> implements CompWarehouseService {



    @Override
    public PageInfo<CompWarehouseDTO> getWarehousePageList(CompWarehouseDTO compWarehouseDTO) {
        Integer pageSize = compWarehouseDTO.getPageSize();
        Integer page = compWarehouseDTO.getPage();
        if (pageSize > 0 && page > 0) {
            PageHelper.startPage(page, pageSize);
        }
        List<CompWarehouseDTO> compWarehouseDTOList =
                baseDao.getWarehousePageList(compWarehouseDTO.getCompId(), compWarehouseDTO.getParam());
        return  new PageInfo<>(compWarehouseDTOList);
    }

    @Override
    public CompWarehouseEntity getWarehouseById(Long compId, Long id) {
        return baseDao.getWarehouseById(compId, id);
    }

    @Override
    @Transactional
    public void addWarehouse(CompWarehouseDTO compWarehouseDTO) {
        CompWarehouseEntity compWarehouseEntity =ConvertUtils
                .sourceToTarget(compWarehouseDTO, CompWarehouseEntity.class);
        insert(compWarehouseEntity);
    }

    @Override
    @Transactional
    public void updateWarehouse(CompWarehouseDTO compWarehouseDTO) {
        CompWarehouseEntity compWarehouseEntity =ConvertUtils
                .sourceToTarget(compWarehouseDTO, CompWarehouseEntity.class);
        updateById(compWarehouseEntity);
    }

    @Override
    public void deleteWarehouse(CompWarehouseDTO compWarehouseDTO) {
        baseDao.deleteWarehouse(compWarehouseDTO.getCompId(), compWarehouseDTO.getId());
    }
}
